package com.mask.mq.config;

import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author hx
 * @since 2021/11/21 1:24 下午
 */

@Configuration
public class RabbitmqConfig {

// -----------------------direct交换机-------------------------------------
    /**
     * 默认direct交换器,轮询
     * @return
     */
//    @Bean
//    protected Queue queue(){
//        return new Queue("myqueue");
//    }


// ------------------------fanout交换机------------------------------------

//    @Bean
//    protected Queue fanoutQueue1(){
//        return new Queue("fanout1");
//    }
//
//    @Bean
//    protected Queue fanoutQueue2(){
//        return new Queue("fanout2");
//    }

    /**
     * fanout交换器 广播模式
     */
//    @Bean
//    protected FanoutExchange fanoutExchange(){
//        return new FanoutExchange("amq.fanout");
//    }

//    交换器绑定
//    @Bean
//    protected Binding fanoutBinding1(Queue fanoutQueue1, FanoutExchange fanoutExchange) {
//        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
//    }
//
//    @Bean
//    protected Binding fanoutBinding2(Queue fanoutQueue2, FanoutExchange fanoutExchange) {
//        return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
//    }

// ------------------------topic交换机------------------------------------

    @Bean
    protected Queue topicQueue1() {
        return new Queue("topic1");
    }

    @Bean
    protected Queue topicQueue2() {
        return new Queue("topic2");
    }

    @Bean
    protected TopicExchange topicExchange() {
        //配置mq交换机为topic
        return new TopicExchange("amq.topic");
    }

    @Bean
    protected Binding topicBinding1(Queue topicQueue1, TopicExchange topicExchange) {
        return BindingBuilder.bind(topicQueue1).to(topicExchange).with("com.a");
    }

    @Bean
    protected Binding topicBinding2(Queue topicQueue2, TopicExchange topicExchange) {
        // *匹配一个单词 #匹配0个或多个
        return BindingBuilder.bind(topicQueue2).to(topicExchange).with("com.b");
    }






}
